package com.shuqing.config;
//import com.shuqing.interceptor.ResourceInterceptor;
import com.shuqing.interceptor.ResourceInterceptor;
import org.springframework.context.annotation.ComponentScan;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.*;

@Configuration
//等同于<context:component-scan base-package="com.shuqing.controller"/>
@ComponentScan({"com.shuqing.controller"})
//等同于<mvc:annotation-driven/>，还不完全相同
@EnableWebMvc
public class SpringMvcConfig implements WebMvcConfigurer{
    /**
     * 开启静态资源访问
     * 类似于在SpringMVC的配置文件中设置<mvc:default-servlet
     handler />
     * @param configurer
     */
    @Override
    public void
    configureDefaultServletHandling(DefaultServletHandlerConfigurer configurer) {
        configurer.enable();
    }
    @Override
    public void configureViewResolvers(ViewResolverRegistry registry) {
        registry.jsp("/admin/", ".jsp");
    }

    /**
     * 添加拦截器 将自定义拦截器添加到配置文件里面
     * @param registry
     */
    @Override
    public void addInterceptors(InterceptorRegistry registry) {
        registry.addInterceptor(new ResourceInterceptor()).addPathPatterns("/**").excludePathPatterns("/css/**","/js/**","/img/**");
    }
}
